home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------
-
- Program name: Menus demonstration program.
-
- Author: Gareth Williams
-
- Description: This program demonstrates box menus, user menus and rotators
- and enables interaction using the pick, locator and string input devices.
-
- Modification history : (Version), (Date), (Name), (Description).
-
- 1.0, 1st March 1991, G. Williams, First Version.
-
- 2.0, June 1992, G. Williams, Converted to ISO PHIGS C.
-
- SunOS requirements: SunPHIGS 2.0, OpenWindows 3.0.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <math.h>
- #include <phigs.h>
- #include "ptk.h"
-
- /* #define SUNMONO */
-
- #define WS1 1
- #define NUMCPTS 19
- #define PI 3.14
-
- /* Operating system dependent code, UNIX/VMS pathnames */
- /* UNIX pathname */
- #define OPENWSNAME "../scripts/openws.scr"
-
- static char *colwrd[] =
- {
- "BLACK", "GREEN",
- "MEDIUM GREEN", "MAGENTA", "MEDIUM MAGENTA",
- "WHITE", "GREY",
- };
-
- static Pint wst;
- static Pint mainmenuid, inputmenuid, boxmenuid, usermenuid, userboxid;
- static Pint rotator1, rotator2, rotator3;
- static Pfloat devx, devy, devz;
- static Plimit3 pointecho;
- static Plimit3 boxport = {0.0, 0.2, 0.0, 0.2, 0.0, 0.1};
- static ptkboolean docolour = FALSE;
-
- /*--------------------------------------------------------------------------*/
-
- static void makecircle(C(Ppoint3 *) centre, C(Pfloat) radius,
- C(Ppoint3 *) pts)
- PreANSI(Ppoint3 *centre)
- PreANSI(Pfloat radius)
- PreANSI(Ppoint3 *pts)
- {
- Pfloat delta;
- Pint i;
-
- delta = 2 * PI / NUMCPTS;
- for (i = 0; i < NUMCPTS; i++)
- {
- pts[i].x = centre->x + radius * cos(i * delta);
- pts[i].y = centre->y + radius * sin(i * delta);
- pts[i].z = centre->z;
- }
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void makeellipse(C(Ppoint3 *) centre, C(Pfloat) xradius,
- C(Pfloat) yradius, C(Ppoint3 *) pts)
- PreANSI(Ppoint3 *centre)
- PreANSI(Pfloat xradius)
- PreANSI(Pfloat yradius)
- PreANSI(Ppoint3 *pts)
- {
- Pfloat delta;
- Pint i;
-
- delta = 2 * PI / NUMCPTS;
- for (i = 0; i < NUMCPTS; i++)
- {
- pts[i].x = centre->x + xradius * cos(i * delta);
- pts[i].y = centre->y + yradius * sin(i * delta);
- pts[i].z = centre->z;
- }
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void shadebox(C(Ppoint3 *) pos, C(Pfloat) height, C(Pfloat) width,
- C(Pfloat) xpercent, C(Pfloat) ypercent,
- C(Pint) tlcol, C(Pint) brcol, C(Pint) mcol)
- PreANSI(Ppoint3 *pos)
- PreANSI(Pfloat height)
- PreANSI(Pfloat width)
- PreANSI(Pfloat xpercent)
- PreANSI(Pfloat ypercent)
- PreANSI(Pint tlcol)
- PreANSI(Pint brcol)
- PreANSI(Pint mcol)
- {
- Ppoint3 pts[6];
- Ppoint_list3 sets;
-
- pset_int_style(PSTYLE_SOLID);
- pset_int_colr_ind(mcol);
- pts[0] = ptk_point3(pos->x - (width / 2.0), pos->y - (height / 2.0),
- pos->z);
- pts[1] = ptk_point3(pts[0].x, pts[0].y + height, pos->z);
- pts[2] = ptk_point3(pts[0].x + width, pts[1].y, pos->z);
- pts[3] = ptk_point3(pts[2].x - (width * xpercent),
- pts[2].y - (height * ypercent), pos->z);
- pts[4] = ptk_point3(pts[1].x + (width * xpercent), pts[3].y, pos->z);
- pts[5] = ptk_point3(pts[4].x, pts[0].y + (height * ypercent), pos->z);
-
- pts[2] = ptk_point3(pts[3].x, pts[5].y, pos->z);
- sets.num_points = 4;
- sets.points = &pts[2];
- pfill_area3(&sets);
-
- pset_edge_flag(PEDGE_ON);
- pset_int_colr_ind(tlcol);
- pset_edge_colr_ind(tlcol);
- pts[2] = ptk_point3(pts[0].x + width, pts[1].y, pos->z);
- sets.num_points = 6;
- sets.points = pts;
- ptk_fillareaset3(1, &sets);
-
- pset_int_colr_ind(brcol);
- pset_edge_colr_ind(brcol);
- pts[1].x += width;
- pts[1].y -= height;
- pts[4].x = pts[3].x;
- pts[4].y = pts[5].y;
- ptk_fillareaset3(1, &sets);
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void makeshademenu()
- {
- Ppoint3 itemcentre, pts[20];
- Pint white, black, green, i;
- Ptext_align align;
- Ppoint txpt, boxpt;
- Pfloat charheight;
- Ppoint_list3 ptlist;
-
- if (docolour)
- {
- white = ptk_stringtoint("colourindex", "white");
- black = ptk_stringtoint("colourindex", "black");
- green = ptk_stringtoint("colourindex", "green");
- }
- else
- {
- white = 1;
- black = 0;
- green = 0;
- }
-
- ptk_openstruct(ptk_stringtoint("structureid", "shademenu1"));
- itemcentre = ptk_point3(0.4, 0.7, 0.0);
- shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
-
- /* dashed line */
- pset_linewidth(3.0);
- pset_linetype(PLINE_DASH);
- pts[0] = ptk_point3(0.35, 0.65, 0.0);
- pts[1] = ptk_point3(0.45, 0.75, 0.0);
- ptlist.num_points = 2;
- ptlist.points = pts;
- ppolyline3(&ptlist);
- ptk_closestruct();
-
- ptk_openstruct(ptk_stringtoint("structureid", "shademenu3"));
- itemcentre.y -= 0.2;
- shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
-
- /* circle */
- makecircle(&itemcentre, 0.05, pts);
- pts[19] = pts[0];
- ptlist.num_points = 20;
- ppolyline3(&ptlist);
- ptk_closestruct();
-
- ptk_openstruct(ptk_stringtoint("structureid", "shademenu5"));
- itemcentre.y -= 0.2;
- shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
-
- /* ellipse */
- makeellipse(&itemcentre, 0.05, 0.025, pts);
- pts[19] = pts[0];
- ppolyline3(&ptlist);
- ptk_closestruct();
-
- ptk_openstruct(ptk_stringtoint("structureid", "shademenu2"));
- itemcentre = ptk_point3(0.6, 0.7, 0.0);
- shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
-
- /* polygon */
-
- pts[0] = ptk_point3(0.55, 0.75, 0.0);
- pts[1] = ptk_point3(0.65, 0.75, 0.0);
- pts[2] = ptk_point3(0.53, 0.63, 0.0);
- pts[3] = ptk_point3(0.67, 0.63, 0.0);
- pts[4] = pts[0];
- ptlist.num_points = 5;
- ppolyline3(&ptlist);
- ptk_closestruct();
-
- ptk_openstruct(ptk_stringtoint("structureid", "shademenu4"));
- itemcentre.y -= 0.2;
- shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
-
- pset_int_colr_ind(white);
- pset_int_style(PSTYLE_HATCH);
- pset_int_style_ind(-5);
- for (i = 0; i < 5; i++)
- pts[i].y -= 0.2;
- ptlist.num_points = 4;
- pfill_area3(&ptlist);
- ptk_closestruct();
-
- ptk_openstruct(ptk_stringtoint("structureid", "shademenu6"));
- itemcentre.y -= 0.2;
- shadebox(&itemcentre, 0.2, 0.2, 0.05, 0.05, white, black, green);
-
- /* capital A */
- boxpt = ptk_point(0.2 - (0.2 * 0.1), 0.2 - (0.2 * 0.1));
- ptk_computecharheight(WS1, "A", &boxpt, -6, &charheight);
- pset_char_ht(charheight);
- pset_text_font(-6);
- align.hor = PHOR_CTR;
- align.vert = PVERT_HALF;
- pset_text_align(&align);
- txpt = ptk_point(itemcentre.x, itemcentre.y);
- ptext(&txpt, "A");
- ptk_closestruct();
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void highlightshadeitem(C(Pint) itemnum)
- PreANSI(Pint itemnum)
- {
- Pint err, tlcol, brcol;
- ptkselcontent elcont;
- Pstore store;
-
- if (itemnum != 0)
- {
- switch (itemnum)
- {
- case 1: ptk_openstruct(ptk_stringtoint("structureid", "shademenu1"));
- break;
-
- case 2: ptk_openstruct(ptk_stringtoint("structureid", "shademenu2"));
- break;
-
- case 3: ptk_openstruct(ptk_stringtoint("structureid", "shademenu3"));
- break;
-
- case 4: ptk_openstruct(ptk_stringtoint("structureid", "shademenu4"));
- break;
-
- case 5: ptk_openstruct(ptk_stringtoint("structureid", "shademenu5"));
- break;
-
- case 6: ptk_openstruct(ptk_stringtoint("structureid", "shademenu6"));
- break;
-
- }
- pset_elem_ptr(5);
-
- pcreate_store(&err, &store);
- ptk_inqcurelemtypesizecontent(store, &err, &elcont);
- tlcol = elcont.eldata->int_data;
- pdel_store(store);
- pset_elem_ptr(8);
- pcreate_store(&err, &store);
- ptk_inqcurelemtypesizecontent(store, &err, &elcont);
- brcol = elcont.eldata->int_data;
- pdel_store(store);
- pset_elem_ptr(5);
- ptk_seteditmode(PEDIT_REPLACE);
- pset_int_colr_ind(brcol);
- poffset_elem_ptr(1);
- pset_edge_colr_ind(brcol);
- pset_elem_ptr(8);
- pset_int_colr_ind(tlcol);
- poffset_elem_ptr(1);
- pset_edge_colr_ind(tlcol);
- ptk_unseteditmode();
- ptk_closestruct();
- }
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void pickinput(C(Pint *) itemnum)
- PreANSI(Pint *itemnum)
- {
- Pin_status status;
- Ppick_path initpath;
- Plimit3 pickecho;
- Ppick_data3 pickrec;
- Ppath_order pickorder;
- Ppick_path pickdata;
- Ppick_path_elem pickarray[10];
- Pint pickpet;
- ptksgeneralinput pickinput;
- ptksmenuoutput pickoutput;
- Pint_list menuset;
- Pint menusetlist[20], menunamelist[20];
- Pint totsize, i, err;
- Pfilter pickfilt;
-
- /* test picking */
- *itemnum = 0;
- printf("Pick a menu item...\n");
- /* initialise pick */
- #ifdef SUN
- status = PIN_STATUS_NONE;
- #endif
- #ifdef HP
- status = PIN_STATUS_NO_IN;
- #endif
- initpath.depth = 0;
- pickecho.x_min = 0.0;
- pickecho.y_min = 0.0;
- pickecho.z_min = 0.0;
- pickecho.x_max = 0.1;
- pickecho.y_max = 0.1;
- pickecho.z_max = 0.1;
- pickorder = PORDER_BOTTOM_FIRST;
-
- pickfilt.excl_set.num_ints = 0;
- pickfilt.incl_set.num_ints = 0;
- menuset.ints = menusetlist;
- pickfilt.incl_set.ints = menunamelist;
- ptk_inqpostedmenus(WS1, 20, &menuset, &totsize, &err);
- for (i = 0; i < totsize; i++)
- {
- ptk_inqmenuname(menuset.ints[i],
- &pickfilt.incl_set.ints[pickfilt.incl_set.num_ints++], &err);
- }
- pset_pick_filter(1, 1, &pickfilt);
-
- #ifdef SUN
- pickpet = 2;
- pickrec.pets.pet_r2.highl_colr = 2;
- pickrec.pets.pet_r2.highl_count = 2;
- pickrec.pets.pet_r2.highl_duration = 0.3;
-
- pickrec.pets.pet_r2.ap_size = 1.0;
-
- #endif
- #ifdef VMS
- pickpet = 1;
- pickrec.pets.pet_r1.aperature = 0.05;
- #endif
- #ifdef HP
- pickpet = 1;
- pickrec.pets.pet_r1.highl_colr_ind = 3;
- pickrec.pets.pet_r1.x_dim = 0.005;
- pickrec.pets.pet_r1.y_dim = 0.005;
- pickrec.pets.pet_r1.z_dim = 2.0;
- #endif
- #ifdef PEXSI
- pickpet = 1;
- #endif
-
- pinit_pick3(1, 1, status, &initpath, pickpet, &pickecho, &pickrec,
- pickorder);
-
- /* set pick */
- pset_pick_mode(1, 1, POP_REQ, PSWITCH_ECHO);
-
- /* request pick */
- pickdata.path_list = pickarray;
-
- preq_pick(1, 1, 10, &status, &pickdata);
-
- if (status == PIN_STATUS_OK)
- {
- pickinput.inputclass = PIN_PICK;
- pickinput.ptkugeninput.ptkspickinput.pickdata = pickdata;
- pickinput.ptkugeninput.ptkspickinput.pathorder = PORDER_BOTTOM_FIRST;
- if (ptk_scanmenus(WS1, &pickinput, &pickoutput))
- {
- printf("menu item %d was picked from menu %d.\n", pickoutput.itemnum,
- pickoutput.menuid);
- *itemnum = pickoutput.itemnum;
- }
- else
- printf("You did not pick a menu.\n");
- }
- else
- printf("Nothing picked.\n");
- }
-
- /*--------------------------------------------------------------------------*/
-
- ptkboolean getmenupick(C(Pint) menuid, C(ptksmenuoutput *) pickoutput)
- PreANSI(Pint menuid)
- PreANSI(ptksmenuoutput *pickoutput)
- {
- Pin_status status;
- Ppick_path initpick;
- Plimit3 pickecho;
- Ppick_data3 pickrec;
- Ppath_order pickorder;
- Ppick_path pickdata;
- Ppick_path_elem pickarray[10];
- Pint pickpet;
- ptksgeneralinput pickinput;
- Pint menusetlist[20];
- Pint totsize;
- char name[30];
- Pfilter pickfilt;
-
- pickfilt.excl_set.num_ints = 0;
- pickfilt.incl_set.num_ints = 1;
- pickfilt.incl_set.ints = menusetlist;
- sprintf(name, "name$menu%d", menuid);
- menusetlist[0] = ptk_stringtoint("name", name);
- pickecho.x_min = 0.0;
- pickecho.y_min = 0.0;
- pickecho.z_min = 0.0;
- pickecho.x_max = 0.1;
- pickecho.y_max = 0.1;
- pickecho.z_max = 0.1;
- #ifdef SUN
- status = PIN_STATUS_NONE;
- #endif
- #ifdef HP
- status = PIN_STATUS_NO_IN;
- #endif
- initpick.depth = 0;
- initpick.path_list = NULL;
- pickorder = PORDER_BOTTOM_FIRST;
- /* make menu pickable */
- pset_pick_filter(1, 1, &pickfilt);
-
- #ifdef SUN
- pickpet = 2;
- pickrec.pets.pet_r2.highl_colr = 2;
- pickrec.pets.pet_r2.highl_count = 2;
- pickrec.pets.pet_r2.highl_duration = 0.2;
-
- pickrec.pets.pet_r2.ap_size = 1.0;
-
- #endif
- #ifdef VMS
- pickpet = 1;
- pickrec.pets.pet_r1.aperature = 0.05;
- #endif
- #ifdef HP
- pickpet = 1;
- pickrec.pets.pet_r1.highl_colr_ind = 3;
- pickrec.pets.pet_r1.x_dim = 0.005;
- pickrec.pets.pet_r1.y_dim = 0.005;
- pickrec.pets.pet_r1.z_dim = 2.0;
- #endif
- #ifdef PEXSI
- pickpet = 1;
- #endif
-
- pinit_pick3(1, 1, status, &initpick, pickpet, &pickecho, &pickrec,
- pickorder);
-
- /* set pick */
- pset_pick_mode(1, 1, POP_REQ, PSWITCH_ECHO);
-
- /* request pick */
- pickdata.path_list = pickarray;
- preq_pick(1, 1, 10, &status, &pickdata);
-
- if (status == PIN_STATUS_OK)
- {
- pickinput.inputclass = PIN_PICK;
- pickinput.ptkugeninput.ptkspickinput.pickdata = pickdata;
- pickinput.ptkugeninput.ptkspickinput.pathorder = PORDER_BOTTOM_FIRST;
- }
- return ptk_scanmenus(WS1, &pickinput, pickoutput);
- }
-
- /*--------------------------------------------------------------------------*/
-
- void pointinput(C(Pint *) itemnum)
- PreANSI(Pint *itemnum)
- {
- /* test locator */
- Pint initview, viewindex;
- Ppoint initpt, locpos;
- Pin_status status;
- Plimit echovol;
- Ploc_data locrec;
- ptksgeneralinput locinput;
- ptksmenuoutput locoutput;
-
- *itemnum = 0;
- printf("Point at a menu item...\n");
- initview = 0;
- initpt = ptk_point(0.5, 0.5);
- echovol.x_min = 0.0;
- echovol.y_min = 0.0;
- echovol.x_max = devx;
- echovol.y_max = devy;
- #ifdef HP
- locrec.pets.pet_r1.loc_colr_ind = 1;
- #endif
- pinit_loc(1, 1, initview, &initpt, 1, &echovol, &locrec);
- pset_loc_mode(1, 1, POP_REQ, PSWITCH_ECHO);
- preq_loc(1, 1, &status, &viewindex, &locpos);
- if (status == PIN_STATUS_OK)
- locinput.inputclass = PIN_LOC;
- locinput.ptkugeninput.locpoint = locpos;
- if (ptk_scanmenus(WS1, &locinput, &locoutput))
- {
- printf("menu item %d was pointed at from menu %d.\n", locoutput.itemnum,
- locoutput.menuid);
- *itemnum = locoutput.itemnum;
- if (locoutput.measure)
- printf("value, x = %f, y = %f\n", locoutput.value.x,
- locoutput.value.y);
- }
- else
- printf("You did not point at a menu.\n");
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void stringinput(C(Pint *) itemnum)
- PreANSI(Pint *itemnum)
- {
- /* test string */
- ptksgeneralinput strinput;
- char dummystr[30];
- Pint dummylen;
- ptksmenuoutput stroutput;
- Plimit echoarea;
-
- *itemnum = 0;
- strinput.inputclass = PIN_STRING;
- printf("Enter a menu item...\n");
- echoarea = ptk_limit(0.0, devx, 0.0, devy * 0.1);
- ptk_readstring(WS1, "", "Type menu item name >", &echoarea,
- 30, dummystr, &dummylen);
- strncpy(strinput.ptkugeninput.str, dummystr, dummylen);
- strinput.ptkugeninput.str[dummylen] = '\0';
- if (ptk_scanmenus(WS1, &strinput, &stroutput))
- {
- printf("menu item %d was entered from menu %d.\n", stroutput.itemnum,
- stroutput.menuid);
- *itemnum = stroutput.itemnum;
- }
- else
- printf("No menu item of that name.\n");
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void makemainmenu(C(void))
- {
- Pint i, err;
- Ppoint topleft;
- Ppoint box;
- Pint numboxes;
- Ptext_path mpath;
- Pint textind;
- Pfloat charht;
- Pint white, black, green;
-
- /* create a BOX menu */
- /* set up main menu - box menu(box, user, rotator, exit) */
- mainmenuid = ptk_stringtoint("menuid", "mainmenu");
- box = ptk_point(0.2, 0.1);
- textind = 1;
- charht = 0.025;
- topleft = ptk_point(0.8, 1.0);
-
- ptk_createboxmenu(mainmenuid, &topleft, &box);
-
- if (docolour)
- {
- white = ptk_stringtoint("colourindex", "white");
- black = ptk_stringtoint("colourindex", "black");
- green = ptk_stringtoint("colourindex", "green");
- ptk_setboxmenuattrs(1, mainmenuid, PPATH_LEFT, -3,
- white, green, green, white, black, white, green, green);
- }
-
- ptk_createtextmenuitem(mainmenuid, "box", 1, PEDIT_INSERT, &err);
- ptk_createtextmenuitem(mainmenuid, "user", 2, PEDIT_INSERT, &err);
- ptk_createtextmenuitem(mainmenuid, "rotator", 3, PEDIT_INSERT, &err);
- ptk_createtextmenuitem(mainmenuid, "exit", 4, PEDIT_INSERT, &err);
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void makeinputmenu(C(void))
- /* create a box menu for selecting a PHIGS input device */
- {
- Pint i, err;
- Ppoint topleft;
- Ppoint box;
- Pint numboxes;
- Ptext_path mpath;
- Pint white, magenta, black, darkmagenta;
-
- inputmenuid = ptk_stringtoint("menuid", "inputmenu");
- box = ptk_point(0.1, 0.05);
- topleft = ptk_point(0.8, 0.5);
-
- ptk_createboxmenu(inputmenuid, &topleft, &box);
-
- if (docolour)
- {
- white = ptk_stringtoint("colourindex", "white");
- magenta = ptk_stringtoint("colourindex", "magenta");
- darkmagenta = ptk_stringtoint("colourindex", "medium magenta");
- black = ptk_stringtoint("colourindex", "black");
- ptk_setboxmenuattrs(1, inputmenuid, PPATH_DOWN, 1, white,
- magenta, magenta, white, black, white, darkmagenta, darkmagenta);
- }
-
- ptk_createtextmenuitem(inputmenuid, "pick", 1, PEDIT_INSERT, &err);
- ptk_createtextmenuitem(inputmenuid, "point", 2, PEDIT_INSERT, &err);
- ptk_createtextmenuitem(inputmenuid, "string", 3, PEDIT_INSERT, &err);
- ptk_createtextmenuitem(inputmenuid, "exit", 4, PEDIT_INSERT, &err);
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void createbox(C(void))
- /* create a box menu with 4 items */
- {
- Pint i, err;
- Ppoint topleft;
- Ppoint box;
- Pint numboxes;
- Ptext_path mpath;
- Pint textind;
- Pfloat charht;
- Pint white, green, black, darkgreen;
-
- boxmenuid = ptk_stringtoint("menuid", "boxmenu");
- box = ptk_point(0.2, 0.1);
- textind = 1;
- charht = 0.03;
- topleft = ptk_point(0.0, 0.0);
-
- ptk_createboxmenu(boxmenuid, &topleft, &box);
-
- if (docolour)
- {
- white = ptk_stringtoint("colourindex", "white");
- green = ptk_stringtoint("colourindex", "green");
- darkgreen = ptk_stringtoint("colourindex", "medium green");
- black = ptk_stringtoint("colourindex", "black");
- ptk_setboxmenuattrs(1, boxmenuid, PPATH_DOWN, 1, white, green, green,
- white, black, white, darkgreen, darkgreen);
- }
-
- topleft = ptk_point(0.5, 0.7);
- ptk_setmenuposition(boxmenuid, &topleft);
-
- ptk_createtextmenuitem(boxmenuid, "item 1", 1, PEDIT_INSERT, &err);
- ptk_createtextmenuitem(boxmenuid, "item 2", 2, PEDIT_INSERT, &err);
- ptk_createtextmenuitem(boxmenuid, "item 3", 3, PEDIT_INSERT, &err);
- ptk_createtextmenuitem(boxmenuid, "item 4", 4, PEDIT_INSERT, &err);
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void createuser(C(void))
- /* create a user menu,
- ** in this case a typical menu for a drawing package.
- */
- {
- Pint userstructid;
- Pint err;
-
- makeshademenu();
- usermenuid = ptk_stringtoint("menuid", "usermenu");
- userstructid = ptk_stringtoint("structureid", "usermenu");
- ptk_createusermenu(usermenuid, userstructid);
- ptk_createstructmenuitem(usermenuid,
- ptk_stringtoint("structureid", "shademenu1"), 1, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(usermenuid,
- ptk_stringtoint("structureid", "shademenu2"), 2, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(usermenuid,
- ptk_stringtoint("structureid", "shademenu3"), 3, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(usermenuid,
- ptk_stringtoint("structureid", "shademenu4"), 4, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(usermenuid,
- ptk_stringtoint("structureid", "shademenu5"), 5, PEDIT_INSERT, &err);
- ptk_createstructmenuitem(usermenuid,
- ptk_stringtoint("structureid", "shademenu6"), 6, PEDIT_INSERT, &err);
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void createrotator(C(void))
- /* create a 1D, 2D and 3D rotator */
- {
- Ppoint size, pos;
- Pint white, black, green;
-
- /* create a rotator */
- rotator1 = ptk_stringtoint("menuid", "1drotator");
- rotator2 = ptk_stringtoint("menuid", "2drotator");
- rotator3 = ptk_stringtoint("menuid", "3drotator");
- size = ptk_point(0.2, 0.2);
-
- ptk_createrotator(WS1, rotator1, PTKEONED, &size, "1D rotator",
- 0.02);
- ptk_createrotator(WS1, rotator2, PTKETWOD, &size, "2D rotator",
- 0.02);
- size = ptk_point(0.3, 0.2);
- ptk_createrotator(WS1, rotator3, PTKETHREED, &size, "3D rotator",
- 0.02);
- if (docolour)
- {
- white = ptk_stringtoint("colourindex", "white");
- black = ptk_stringtoint("colourindex", "black");
- green = ptk_stringtoint("colourindex", "green");
- ptk_setrotatorattrs(WS1, rotator1, 1, white, green, white, green,
- white, green, white, black);
- ptk_setrotatorattrs(WS1, rotator2, 1, white, green, white, green,
- white, green, white, black);
- ptk_setrotatorattrs(WS1, rotator3, -3, white, green, white, green,
- white, green, white, black);
- }
- pos = ptk_point(0.5, 0.3);
- ptk_setmenuposition(rotator1, &pos);
- pos = ptk_point(0.5, 0.55);
- ptk_setmenuposition(rotator2, &pos);
- pos = ptk_point(0.5, 0.8);
- ptk_setmenuposition(rotator3, &pos);
- ptk_setrotatortitle(rotator1, "zoom");
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void testboxmenu(C(void))
- /* enable pick, locator and string input on box menus,
- ** Menu items on the input menu and box menu are highlighted
- ** when selected.
- */
- {
- ptkboolean boxmenuquit;
- ptksmenuoutput output;
- Pint itemnum, err;
-
- ptk_unpostmenu(WS1, mainmenuid);
- ptk_postmenu(WS1, inputmenuid);
-
- ptk_postmenu(WS1, boxmenuid);
- ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
- boxmenuquit = FALSE;
- do
- {
- output.itemnum = 0;
- if (getmenupick(inputmenuid, &output))
- {
- ptk_setboxmenuhighlightitem(inputmenuid, output.itemnum);
- ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
- switch (output.itemnum)
- {
- case 1: pickinput(&itemnum);
- ptk_setboxmenuhighlightitem(boxmenuid, itemnum);
- break;
- case 2: pointinput(&itemnum);
- ptk_setboxmenuhighlightitem(boxmenuid, itemnum);
- break;
- case 3: stringinput(&itemnum);
- ptk_setboxmenuhighlightitem(boxmenuid, itemnum);
- break;
- case 4: boxmenuquit = TRUE;
- break;
- }
- ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
- }
- } while (!boxmenuquit);
- ptk_clearboxmenuhighlight(inputmenuid);
- ptk_clearboxmenuhighlight(boxmenuid);
- ptk_unpostmenu(WS1, boxmenuid);
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void testusermenu(C(void))
- /* enable pick, locator and string input on user menu.
- ** The invisibility filter is used to hide the main menu.
- */
- {
- ptkboolean usermenuquit;
- ptksmenuoutput output;
- Pint err, itemnum, lastitemnum, stid, invismenu;
- char name[20];
- Pfilter invisfilt;
-
- invisfilt.excl_set.num_ints = 0;
- invisfilt.excl_set.ints = NULL;
- invisfilt.incl_set.num_ints = 1;
- invisfilt.incl_set.ints = &invismenu;
- lastitemnum = itemnum = 0;
-
- sprintf(name, "name$menu%d", mainmenuid);
- invismenu = ptk_stringtoint("name", name);
- pset_invis_filter(WS1, &invisfilt);
- ptk_postmenu(WS1, inputmenuid);
-
- ptk_postmenu(WS1, usermenuid);
- ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
- usermenuquit = FALSE;
- do
- {
- output.itemnum = 0;
- if (getmenupick(inputmenuid, &output))
- {
- switch (output.itemnum)
- {
- case 1: pickinput(&itemnum);
- break;
- case 2: pointinput(&itemnum);
- break;
- case 3: stringinput(&itemnum);
- break;
- case 4: usermenuquit = TRUE;
- break;
- }
- highlightshadeitem(lastitemnum);
- highlightshadeitem(itemnum);
- lastitemnum = itemnum;
- ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
- }
- } while (!usermenuquit);
- highlightshadeitem(lastitemnum);
- invisfilt.incl_set.num_ints = 0;
- pset_invis_filter(WS1, &invisfilt);
- ptk_unpostmenu(WS1, usermenuid);
- }
-
- /*--------------------------------------------------------------------------*/
-
- static void testrotator(C(void))
- /* enable pick and locator input on rotators */
- {
- ptkboolean rotatorquit;
- ptksmenuoutput output;
- Pint err, itemnum;
-
- ptk_delmenuitem(inputmenuid, 3);
- ptk_unpostmenu(WS1, mainmenuid);
- ptk_postmenu(WS1, inputmenuid);
-
- ptk_postmenu(WS1, rotator1);
- ptk_postmenu(WS1, rotator2);
- ptk_postmenu(WS1, rotator3);
- ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
- rotatorquit = FALSE;
- do
- {
- output.itemnum = 0;
- if (getmenupick(inputmenuid, &output))
- switch (output.itemnum)
- {
- case 1: pickinput(&itemnum);
- break;
- case 2: pointinput(&itemnum);
- break;
- case 3: rotatorquit = TRUE;
- break;
- }
- } while (!rotatorquit);
- ptk_unpostmenu(WS1, rotator1);
- ptk_unpostmenu(WS1, rotator2);
- ptk_unpostmenu(WS1, rotator3);
- ptk_createtextmenuitem(inputmenuid, "string", 3, PEDIT_INSERT, &err);
- }
-
- /*--------------------------------------------------------------------------*/
-
- main()
- {
- Pedit_mode mode;
- Pint err;
- Pint_bundle rotintrep, boxintrep;
- Ptext_bundle textrep;
- Pedge_bundle rotedgerep, boxedgerep;
- ptkboolean menuquit;
- ptksmenuoutput output;
- Pws_st_tables lens;
-
- /* open PHIGS */
- printf("Demonstrating the menus utility of the PHIGS Toolkit...\n");
-
- /* Implementation dependent code, open PHIGS and workstation */
- #ifdef SUN
- printf("Opening SunPHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
- #ifdef PEXSI
- printf("Opening PEX-SI PHIGS...\n");
- popen_phigs(PDEF_ERR_FILE, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
- #ifdef HP
- printf("Opening HP PHIGS...\n");
- popen_phigs(stderr, PDEF_MEM_SIZE);
-
- /* open the workstation */
- ptk_readphinterscript(OPENWSNAME, NULL, NULL);
- #endif
-
- pset_disp_upd_st(WS1, PDEFER_WAIT, PMODE_NIVE);
-
- /* set up required hashtables */
- ptk_inithashtables();
- ptk_createhashtable("structureid", 0, 100);
- ptk_createhashtable("viewindex", 1, 100);
- ptk_createhashtable("label", 0, 100);
- ptk_createhashtable("colourindex", 1, 100);
- ptk_createhashtable("name", 1, 100);
- ptk_createhashtable("menuid", 1, 100);
-
- ptk_inqmaxdevicecoords(WS1, &devx, &devy);
- devz = 0.0;
- pointecho.x_min = pointecho.y_min = pointecho.z_min = 0.0;
- pointecho.x_max = devx;
- pointecho.y_max = devy;
- pointecho.z_max = devz;
-
- #ifdef VMS
- pinq_ws_st_table(wst, &err, &lens);
- if (lens.colr > 9)
- docolour = TRUE;
- #endif
- #ifdef SUN
- #ifndef SUNMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef HP
- #ifndef HPMONO
- docolour = TRUE;
- #endif
- #endif
- #ifdef PEXSI
- #ifndef PEXSIMONO
- docolour = TRUE;
- #endif
- #endif
-
- /* set colours */
- if (docolour)
- {
- ptk_setupcolourtable(WS1, 7, colwrd);
- ptk_setbackgroundcolourind(WS1, ptk_stringtoint("colourindex", "grey"));
- }
-
- /* menus to select type of menu and type of input */
-
- makemainmenu();
-
- makeinputmenu();
-
- /* create box, user and rotator menus */
-
- createbox();
-
- createuser();
-
- createrotator();
-
- /* interaction loop */
- menuquit = FALSE;
- do
- {
- ptk_postmenu(WS1, mainmenuid);
- ptk_unpostmenu(WS1, inputmenuid);
- pupd_ws(WS1, PFLAG_PERFORM);
- ptk_redrawallstructs(WS1, PFLAG_ALWAYS);
- output.itemnum = 0;
- if (getmenupick(mainmenuid, &output))
- switch (output.itemnum)
- {
- case 1: testboxmenu();
- break;
- case 2: testusermenu();
- break;
- case 3: testrotator();
- break;
- case 4: menuquit = TRUE;
- break;
- }
- } while (!menuquit);
-
- pclose_ws(WS1);
- printf("Closing PHIGS...\n");
- pclose_phigs();
- exit(0);
- }
-
- /*--------------------------------------------------------------------------*/
-
- /* end of menutest.c */
-